﻿using System;
using System.Data;
using System.Collections.Generic;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;
using MySql.Data;
using System.Data.Odbc;
using MySql.Data.MySqlClient;

namespace KPIS.GERP.GHRMS.DAL
{
    public class orgchartDAL : IorgchartDAL
    {
        private IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString); 
        private MySqlConnection conn = new MySqlConnection(SystemInfo._ConnectionString);

        public DataTable LoadJobSite(int? emp_seq)
        {
            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;
                cmd.CommandText = "hr_sp_evaluate_orgchart_sel";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@emp_seq", emp_seq);
                cmd.Parameters.AddWithValue("@vharRecordStatus", SystemInfo._DeleteRecordStatus);

                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataTable dtb = new DataTable();
                da.Fill(dtb);

                return dtb;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }

        public DataTable LoadNote(int? emp_seq)
        {
            string strSQL;

           try
           {
              dbManager.Open();
              dbManager.CreateParameters(2);

              dbManager.AddParameters(0, "@emp_seq", emp_seq );
              dbManager.AddParameters(1, "@status", SystemInfo._DeleteRecordStatus);

               strSQL = "SELECT * FROM hrm_mp_positions "
                        + " WHERE record_status <> 'D' ";
                       //+ "and job_site_type_seq = 2 ";

               DataTable dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
               return dtb;
           } 
            catch(Exception er)
            {
                throw er;
            }
            finally
           {
               dbManager.Dispose();
           }
        }
    }
}